package yawning.mew.bear;

import yawning.mew.sim.SimulationAction;
import yawning.mew.sim.SimulationEventAction;

public class EnrageAction extends SimulationEventAction {
	BearThreatSimulator mState;
	double mCooldownExpireTime;
	private double mKotJMult;

	EnrageAction(BearThreatSimulator state) {
		super(state.mSimEngine);
		mState = state;

		mKotJMult = 1.0 + state.mModel.mToon.getTalent(BearModel.KINGOFTHEJUNGLE) * 0.05;
	}

	@Override
	public double perform() {
		if (isUp() || mCooldownExpireTime > mState.mSimEngine.getSimTime()) return SimulationAction.ACTION_FAIL;
		if (mState.mIsLogging) mState.mLog.log("Enrage\n");

		mNrEnrage++;

		mRageGained += 20;
		mState.onRageGainThreat(20);
		mState.onPrimalMadnessGain();

		schedule(mState.mModel.enrageBuffDuration, 1.0);

		mCooldownExpireTime = mState.mSimEngine.getSimTime() + mState.mModel.enrageCDDuration;

		return 0.0;
	}

	@Override
	public void onExpire() {
		if (mState.mIsLogging) mState.mLog.log("Enrage Expiration\n");
		mState.onPrimalMadnessLoss();
	}

	@Override
	public void onTick() {
		mRageGained++;
		mState.onRageGainThreatApplyMult(1);
	}

	public double getMult() {
		return isUp() ? mKotJMult : 1.0;
	}

	int mNrEnrage = 0;
	long mRageGained;
}